Re: Write to file & Change Directory



All,

I hope you realize what you're doing is very naughty :). You can get it
working, of course, but the do_*() functions operate in context of the
calling process, and operate on the sent message directly. If you're in
a system call, your creat etc. calls will operate in the context of
that process, which is actually what you want, but is very messy, and
you have to realize what's happening if you're ever going to get it to
work.

buffer is a general type pointer (pointer to void).
Actually it belongs to the struct of type message, and is declared as:
#define buffer m.m1_p1
So, before initializing, I have to declare what type of pointer it will
be.

If I just type strcpy(buffer,"text"); then on the file I am supposed to
write, the only thing written are spaces! If I type
strcpy((char)buffer,"text"); garbage characters are written!

The problem is that do_write() will interpret buffer as a pointer in
the virtual address space of the caller. It's not a pointer in FS
address space. So you're strcpy()ing to more or less random places in
FS. Casting it to (char) just makes matters different, but not
better :).

A neater solution is for the user process that does your new system
call to creat() the file for you, and pass the fd it gets to your new
system call, as well as a buffer in his own address space. Then you can
copy whatever you want to write to the file into that buffer, and call
do_write(). It's not an oil painting, but prettier than what you're
trying above ;-).

=Ben



.



Relevant Pages

  • [patch] x86, ptrace: PEBS support
    ... BTS and PEBS recording. ... * - buffer overflow handling ... (interrupt occurs when write pointer passes interrupt pointer) ... * guarding context and buffer memory allocation. ...
    (Linux-Kernel)
  • Re: some unanswered questions on C
    ... but what exactly is an uninitialised pointer? ... You've said that localvar is a pointer to an int, ... > what i want to ask is that when i declare my buffer for fgets as ... but you haven't declared any space for the buffer. ...
    (comp.unix.programmer)
  • Re: unknown software exception with SampleGrabber
    ... > to declare the class global. ... > How do I get a pointer to the buffer, where I can work on the buffer? ... > I have read something about in the SampleCB function, ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: unknown software exception with SampleGrabber
    ... I created the class c_GrabberCB inside the function AddGrabber, ... to declare the class global. ... How do I get a pointer to the buffer, where I can work on the buffer? ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: strings
    ... the pointer? ... In this context, *buffer is applying the indirection or dereferencing ... character of the string. ...
    (comp.lang.c)