From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27969 invoked by alias); 12 Nov 2013 22:59:48 -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 27960 invoked by uid 89); 12 Nov 2013 22:59:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.2 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,RDNS_NONE,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-bk0-f47.google.com Received: from Unknown (HELO mail-bk0-f47.google.com) (209.85.214.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 12 Nov 2013 22:59:47 +0000 Received: by mail-bk0-f47.google.com with SMTP id mx10so4828bkb.20 for ; Tue, 12 Nov 2013 14:59:38 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.204.103.199 with SMTP id l7mr27866119bko.11.1384297178322; Tue, 12 Nov 2013 14:59:38 -0800 (PST) Received: by 10.204.245.195 with HTTP; Tue, 12 Nov 2013 14:59:38 -0800 (PST) In-Reply-To: References: Date: Tue, 12 Nov 2013 22:59: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/msg00053.txt.bz2 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 --