* Re: silly memory question ...
[not found] <Pine.LNX.3.95.1010828101642.13417A-100000@chaos.analogic.com>
@ 2001-08-28 14:47 ` Josh Fryman
0 siblings, 0 replies; 2+ messages in thread
From: Josh Fryman @ 2001-08-28 14:47 UTC (permalink / raw)
To: linux-kernel
hi all,
thanks to all of you for your suggestions... it turns out this
is an ARM-specific issue, and maybe some other platforms as well.
(or maybe just my specific ARM kernel/glibc combo. ;)
it turns out x86 ignores some "modes" for pages in memory. or
maybe ld.so doesn't bother to set them. anyway, the code snippet
below "fixes" the pages i need fixed to become R/W/X.
on *my* ARM, you can't default execute data pages; you can't
write text pages; etc, etc. (my kernel is 2.4.0 with glibc 2.1.2.)
i don't know what other platforms enforce this, but hopefully
this is as educational for those suggesting solutions as it has
been for me. if i had specified i was running on ARM originally,
it may have made things clearer.
thanks again,
josh
// fix permissions on __app_code - we need R/W/X, not just R/X ...
// ARM-specific problem, but this fix should work on ALL platform targets
printf("Fixing TEXT segment permissions for R/W/X....\n");
for (i=0; i<APP_CODE_K*1024/PAGESIZE; i++)
{
code = (ui32*) ((((ui32)__app_code + i*PAGESIZE) - 1) & ~(PAGESIZE-1));
if (mprotect( code, PAGESIZE, PROT_READ|PROT_WRITE|PROT_EXEC) )
{
printf("mprotect() on 0x%08x failed!\nerrno (%d) indicates status: ", code, errno);
switch (errno)
{
case EINVAL: printf("EINVAL: not valid ptr, or not multiple of PAGESIZE (%d)\n", PAGESIZE);
break;
case EFAULT: printf("EFAULT: memory can not be accessed.\n");
break;
case EACCES: printf("EACCES: memory can not be given specified access modes.\n");
break;
case ENOMEM: printf("ENOMEM: internal kernel structures could not be allocated.\n");
break;
default: printf("??????: unknown error result.\n");
}
exit( CLNT_MPROT_FAIL );
}
}
note:
the dummy "nop" function "__app_code()" is APP_CODE_K in size of
KBs of NOPs.
note 2:
i hope the KiB/MiB/whatever standard suggestion is never adopted
and revoked really soon now.
^ permalink raw reply [flat|nested] 2+ messages in thread
* silly memory question ...
@ 2001-08-27 18:24 Josh Fryman
0 siblings, 0 replies; 2+ messages in thread
From: Josh Fryman @ 2001-08-27 18:24 UTC (permalink / raw)
To: linux-kernel
hi all,
i'm looking to do something stupid. can anyone tell me why it won't
work? (is there some kind of special protection on EXE memory pages?)
i have an application, App1, that has a 64KB function (64KB of NOP)
"void funcX(void)". App1 opens a socket to another application, App2,
which is going to feed code to App1 to stick in funcX.
that is, i've got some other set of functions i plan on feeding to App1
and they're all going to look like "funcX" to App1. those functions are
coming from App2, which is chewing on a bunch of var-things to spit out
just the right code for App1.
now, when i try to do this, i get Random Stuff. sometimes, i just get
a segfault. sometimes, it seems to work, but the memory at funcX is
hosed if i do a hex-dump compared to what i received from App2. either
way, it isn't doing what i want...
is there some trick here to make this work? or am i SOL?
[is there a better place to ask this question?]
thanks,
josh
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-08-28 14:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <Pine.LNX.3.95.1010828101642.13417A-100000@chaos.analogic.com>
2001-08-28 14:47 ` silly memory question Josh Fryman
2001-08-27 18:24 Josh Fryman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).