在x64和x86中使用可变参数arg来处理非类函数

时间:2019-01-11 08:51:51

标签: c++ assembly

我的目标是减少正在编写的DLL(Windows,MSVC)的文件大小。

我要导出的函数数量非常多(> 10,000)。我目前正在使用.DEF文件执行此操作,并通过序数导出(因为按名称导出会极大地增加文件大小)。

无论如何,要导出的功能看起来像这样:

<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Annotation\Groups;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use App\Controller\CreateImageAction;

/**
 * @ORM\Entity(repositoryClass="App\Repository\ImageRepository")
 * @ApiResource(iri="http://schema.org/MediaObject", collectionOperations={
 *     "get",
 *     "post"={
 *         "method"="POST",
 *         "path"="/images",
 *         "controller"=CreateImageAction::class,
 *         "defaults"={"_api_receive"=false},
 *     },
 * })
 * @Vich\Uploadable
 */
class Image
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     * @Groups({"user"})
     */
    private $id;

    /**
     * @var File|null
     * @Vich\UploadableField(mapping="image", fileNameProperty="contentUrl")
     */
    public $file;

    /**
     * @var string|null
     * @ORM\Column(nullable=true)
     * @ApiProperty(iri="http://schema.org/contentUrl")
     * @Groups({"user"})
     */
    private $contentUrl;

    public function getId(): ?int { return $this->id; }
    public function getContentUrl(): ?string { return $this->contentUrl; }

    public function setContentUrl(?string $contentUrl = null): void { $this->contentUrl = $contentUrl; }
}

现在每个export ## i声明仍然包含很多-几乎相同的-指令,导致DLL的大小开销不可忽略,因此我试图确定是否可以进一步缩小。

脑海中浮现了思想;传递给DoSomeWork()的附加标识参数使它有些复杂(## 1-尽管它可以是原始函数的任何唯一标识符,所以它的地址也可以是其他任何标识符)。

#define MK_FUNC(i) extern "C" T_RESULT* export##i(T_ARG* arg0, ...) \
{ \
  va_list va; \
  va_start(va, arg0); \
  auto result = DoSomeWork( ##i, arg0, va ); \
  va_end(va); \
  return result; \
} \


MK_FUNC(0);
MK_FUNC(1);
MK_FUNC(2);
// ....

这完全可以吗?如果是这样,我如何实现跳转到ThunkedCall的目标? 我想由于可变参数会导致常规函数调用不可行(也可能会慢一些,但这并不是主要问题)。 我可能只需要一个asm“ jmp”指令之类的东西?但是再说一次,在x64下没有带MSVC的内联程序集,因此我现在迷失了如何实现它的方法。

谢谢!

0 个答案:

没有答案