From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30498 invoked by alias); 12 Nov 2013 23:00:53 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 30327 invoked by uid 89); 12 Nov 2013 23:00:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.1 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,RDNS_NONE,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-bk0-f42.google.com Received: from Unknown (HELO mail-bk0-f42.google.com) (209.85.214.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 12 Nov 2013 23:00:46 +0000 Received: by mail-bk0-f42.google.com with SMTP id w16so2597270bkz.29 for ; Tue, 12 Nov 2013 15:00:37 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.205.37.132 with SMTP id te4mr4042924bkb.29.1384297237172; Tue, 12 Nov 2013 15:00:37 -0800 (PST) Received: by 10.204.245.195 with HTTP; Tue, 12 Nov 2013 15:00:37 -0800 (PST) In-Reply-To: References: Date: Tue, 12 Nov 2013 23:00:00 -0000 Message-ID: Subject: Re: back into the thread.... From: Mark Manning To: Sterling Augustine Cc: gdb@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes X-SW-Source: 2013-11/txt/msg00054.txt.bz2 disregard, you pasted in the new copy but missed the initial # on the first include. i also missed that :) On Tue, Nov 12, 2013 at 5:59 PM, Mark Manning wrote: > 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 > wrote: >> On Tue, Nov 12, 2013 at 2:42 PM, Sterling Augustine >> 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 >> #include >> #include >> #include >> #include >> >> 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 -- -- "When something can be read without effort, great effort has gone into its writing." -- Enrique Jardiel Poncela --