From: Mark Manning <mark4th@gmail.com>
To: Sterling Augustine <saugustine@google.com>
Cc: gdb@sourceware.org
Subject: Re: back into the thread....
Date: Tue, 12 Nov 2013 22:59:00 -0000 [thread overview]
Message-ID: <CAPGNrUX+pYbf5V7_p50uRy_3vL33ZYYJUCxwbzaFtw0sMc6nEA@mail.gmail.com> (raw)
In-Reply-To: <CAEG7qUyR8OZ=XGy0WwK=1UW46afS=e-67Hs=P3XToxKA1Q9+Pw@mail.gmail.com>
tried to compile your code but all i get is about 400 errors related
to error unknown type name 'size_t' from stdlib.h.
On Tue, Nov 12, 2013 at 5:47 PM, Sterling Augustine
<saugustine@google.com> wrote:
> On Tue, Nov 12, 2013 at 2:42 PM, Sterling Augustine
> <saugustine@google.com> wrote:
>> This feature clearly works.
>>
>
> .. This time with a couple of cleanups. The old example definitely
> works, this just eliminates an extraneous call to malloc and an
> uninitialized variable.
>
> include <stdio.h>
> #include <stdlib.h>
> #include <sys/mman.h>
> #include <string.h>
> #include <malloc.h>
>
> const char bytes[] = { 0x89, 0xf8, 0xc3 };
> #define EXEC_BYTES sizeof(bytes)
>
> typedef int(*function_ptr)(int);
>
> int main(int argc, char *argv[])
> {
> int test_val = 5;
> int return_val;
> function_ptr dst;
> if (posix_memalign((void **) &dst, 4096*8, EXEC_BYTES) != 0) {
> printf("can't allocate.\n");
> exit (-1);
> }
> if (mprotect(dst, EXEC_BYTES, PROT_READ|PROT_WRITE|PROT_EXEC) != 0) {
> printf("can't mprotect\n");
> exit (-1);
> }
>
> if (argc > 1)
> test_val = atoi(argv[1]);
>
> memcpy(dst, bytes, EXEC_BYTES);
>
> return_val = dst(test_val);
> printf("return val was %d\n", return_val);
> return 0;
> }
--
"When something can be read without effort,
great effort has gone into its writing."
-- Enrique Jardiel Poncela --
next prev parent reply other threads:[~2013-11-12 22:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-12 22:09 Mark Manning
2013-11-12 22:42 ` Sterling Augustine
2013-11-12 22:47 ` Sterling Augustine
2013-11-12 22:59 ` Mark Manning [this message]
2013-11-12 23:00 ` Mark Manning
[not found] ` <CAPGNrUUYWR7AOcFwTSxdEZa47E8iUJyfhzhWs+6jSc2+f4xqrg@mail.gmail.com>
2013-11-12 23:10 ` Sterling Augustine
2013-11-12 23:09 ` Mark Manning
2013-11-13 6:48 ` Phi Debian
2013-11-13 12:29 ` Mark Manning
2013-11-13 12:54 ` Phi Debian
2013-11-13 12:59 ` Mark Manning
2013-11-14 17:19 ` Arnab Bhaduri
2013-11-12 22:55 ` Mark Manning
2013-11-13 10:34 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPGNrUX+pYbf5V7_p50uRy_3vL33ZYYJUCxwbzaFtw0sMc6nEA@mail.gmail.com \
--to=mark4th@gmail.com \
--cc=gdb@sourceware.org \
--cc=saugustine@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox