Re: Write System Pointer to User Space
Dave McKenzie <[email protected]>
| Newsgroups | gmane.comp.lang.as400.mi |
|---|---|
| Message-ID | <[email protected]> |
Hi Peter,
Here's a pgm that does that. The "memcpy" function does the equivalent
of a CPYBWP (Copy Bytes With Pointers) MI instruction under the covers.
Note that pointers have to be on 16-byte boundaries. If you declare
them as pointers in your structure (not as a string or something else)
the C compiler will align them properly, even with "_Packed".
--Dave
/*----------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <milib.h>
#include <mih/rslvsp>
#include <mih/setsppfp>
typedef _Packed struct {
int anInt;
_SYSPTR aSyp;
char aStr[9];
} struc_t;
/*----------------------------------------------*/
void main(int argc, char **argv)
{
_SYSPTR spcSyp;
_SPCPTR spcSpp;
_RSLV_Template_T rslvTmplt;
struc_t struc;
/* Get a space ptr to the *usrspc */
rslvTmplt.Obj.Type_Subtype = _Usrspc;
memset(rslvTmplt.Obj.Name, ' ', sizeof(rslvTmplt.Obj.Name));
memcpy(rslvTmplt.Obj.Name, "AUSRSPC", 7);
rslvTmplt.Auth = _AUTH_RETRIEVE;
_RSLVSP2(&spcSyp, &rslvTmplt);
spcSpp = _SETSPPFP(spcSyp);
/* Get a system ptr to a *pgm */
rslvTmplt.Obj.Type_Subtype = _Program;
memset(rslvTmplt.Obj.Name, ' ', sizeof(rslvTmplt.Obj.Name));
memcpy(rslvTmplt.Obj.Name, "APGM", 4);
rslvTmplt.Auth = _AUTH_RETRIEVE;
_RSLVSP2(&struc.aSyp, &rslvTmplt);
memcpy(struc.aStr, "some data", 9);
struc.anInt = 42;
/* Copy the structure (with the pointer) to the *usrspc */
memcpy(spcSpp, &struc, sizeof(struc));
return;
}
Peter Daransky wrote:
> Hi,
> I try to write resolved system pointer of one object to user space ...
> But it doesn't work for me!? Better sayed i've a C structure with many
> variables and my wish is write it complet as a block of data to user
> space, so that i can later read it with the resolved pointer ...
> Do i need perform something special (API or MI instruction ...) ?
> Has someone done something similar ?
> A little example in C will be help :-)
>
> Thank you
> peter_
>
_______________________________________________
This is the MI Programming on the AS400 / iSeries (MI400) mailing list
To post a message email: MI400-Zwy7GipZuJhWk0Htik3J/[email protected]
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/mi400
or email: MI400-request-Zwy7GipZuJhWk0Htik3J/[email protected]
Before posting, please take a moment to review the archives
at http://archive.midrange.com/mi400.