This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: back into the thread....
- From: Mark Manning <mark4th at gmail dot com>
- To: Sterling Augustine <saugustine at google dot com>
- Cc: gdb at sourceware dot org
- Date: Tue, 12 Nov 2013 17:59:38 -0500
- Subject: Re: back into the thread....
- Authentication-results: sourceware.org; auth=none
- References: <CAPGNrUX7TA-4eCrrP=sD9G6oNe5Kw=eWPm_jm-D7=9ZTz-v6BA at mail dot gmail dot com> <CAEG7qUx69s2cdp4XY3cGtAakDQAoSrGnbhgvvLxUzZG+rJKC_g at mail dot gmail dot com> <CAEG7qUyR8OZ=XGy0WwK=1UW46afS=e-67Hs=P3XToxKA1Q9+Pw at mail dot gmail dot 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 --