0

GCC 允许您使用&&. ICC有类似的功能吗?我还没有找到任何关于它的文档。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <stdint.h>

int main(int argc, char **argv)
{
  int (*my_printf) (const char *format, ...);
  void (*my_exit) (int);
  void *page = (void *) ((unsigned long) (&&checkpoint) & ~(getpagesize() - 1));

  /* mark the code section we are going to overwrite                                           
   * as writable.                                                                              
   */
  mprotect(page, getpagesize(), PROT_READ | PROT_WRITE | PROT_EXEC);

  /* Use the labels to avoid having GCC                                                        
   * optimize them out */
  switch (argc) {
  case 33:
    goto checkpoint;
  case 44:
    goto newcode;
  case 55:
    goto newcode_end;
  default:
    break;
  }

  /* Replace code in checkpoint with code from                                                 
   * newcode.                                                                                  
   */
  //memcpy(&&checkpoint, &&newcode, &&newcode_end - &&newcode);                                

 checkpoint:
  printf("Good morning!\n");
  return 1;

 newcode:
  my_printf = &printf;
  (*(my_printf)) ("Good evening\n");

  my_exit = &exit;
  (*(my_exit)) (0);

 newcode_end:
  return 2;
}
4

1 回答 1

0

ICC 的 Linux 版本也支持这一点。相同的语法:

void* ptr = &&some_label;
于 2013-07-21T18:41:28.260 回答