•  Back 
  •  Programming with MiNT 
  •  Index 
  •  Tree View 
  •  Cross references 
  •  Help page 
  •  Show info about hypertext 
  •  View a new file 
Topic       : FreeMiNT Programmer's Guide
Author      : Draco (draco@atari.org)
Version     : mint-prg.stg (english) (31/3/2000)
Subject     : Documentation/Manual
Nodes       : 43
Index Size  : 1474
HCP-Version : 3
Compiled on : Atari
@charset    : atarist
@lang       : 
@default    : 
@help       : 
@options    : -i -s +zz -t4
@width      : 75
View Ref-FileII.5. Using u:\proc

    You can use Fopen() on u:\proc\*.<pid> to get a file handle
    to a process. Then you can use Fcntl() to get and set things
    about that process by an access to its internal PROC
    structure, that is created by MiNT individually for each
    process. An example program using that structure may begin as
    follows:

#include <osbind.h>
#include <mintbind.h>
#include <filesys.h>    /* for PBASEADDR and other constants   */
#include <uproc.h>      /* for struct PROCESS and other things */

long baseaddr, ctxtsize, procaddr, flags;
char buf[14];
int fd;
PROCESS proc;       /* structure from uproc.h */
CONTEXT ctxt;

    To identify files appearing inside the proc folder it is
    enough to pass its process id as the filename extender.
    Here's an example of opening the PROC structure of the
    current process:

sprintf(buf,"u:\\proc\\*.%03d",(int)Pgetpid());
fd = Fopen(buf,2);

    The following functions allow to access particular fields of
    the PROC structure using the file descriptor obtained as
    shown above. If the process terminates, then the descriptor
    becomes invalid.

Fcntl(fd,&baseaddr,PBASEADDR);
    Stores the basepage address of the process in baseaddr
    variable.

Fcntl(fd,&ctxtsize,PCTXTSIZE);
    Stores the size of a MiNT context in ctxtsize.

Fcntl(fd,&procaddr,PPROCADDR);
    Puts the address of the MiNT process structure for the
    process in procaddr. To read the entire process structure
    (defined in proc.h), do this:

Fseek(procaddr,fd,0);
Fread(fd,sizeof(proc),&proc);

    To read the user context (registers, etc.) do this:

Fseek(procaddr-ctxtsize,fd,0);
Fread(fd,sizeof(ctxt),&ctxt);

    To read any part of the memory owned by the process, do this:

Fseek(addr,fd,0);
Fread(fd,size,buffer);
    This Fread will only work if the region you want to read is
    in fact owned by the process that fd refers to.

Fcntl(fd,&flags,PGETFLAGS);
    Puts the low 16 bits of a process' PRGFLAGS into flags.

Fcntl(fd,&flags,PSETFLAGS);
    Sets the low 16 bits of a process' PRGFLAGS from flags. Also
    see Chapter V., Memory protection for detailed information on
    PRGFLAGS field in MiNT.

    If you Fopen() process zero (MiNT itself) then you can
    Fseek() to any address that is managed by MiNT and read or
    write there. This is for debuggers and similarly dangerous
    tools. See also Chapter V., Debugging for other uses of
    u:\proc.