ICC中标签的地址

时间:2013-07-21 18:34:09

标签: c++ gcc icc

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;
}

1 个答案:

答案 0 :(得分:0)

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

void* ptr = &&some_label;