分享方式:


__segmentlimit

Microsoft 特定的

產生 lsl [負載區段限制] 指示。

語法

unsigned long __segmentlimit(
   unsigned long a
);

參數

a
[in]指定區段選取器的常數。

傳回值

如果選取器有效且顯示在目前許可權層級,則為 指定的區段選取器區段限制。

需求

內建 架構
__segmentlimit x86、x64

頭檔<intrin.h>

備註

如果無法擷取區段限制,此指令就會失敗。 失敗時,此指令會清除 ZF 旗標,且傳回值未定義。

此常式僅可作為內建常式使用。

範例

#include <stdio.h>

#ifdef _M_IX86
typedef unsigned int READETYPE;
#else
typedef unsigned __int64 READETYPE;
#endif

#define EFLAGS_ZF      0x00000040
#define KGDT_R3_DATA    0x0020
#define RPL_MASK        0x3

extern "C"
{
unsigned long __segmentlimit (unsigned long);
READETYPE __readeflags();
}

#pragma intrinsic(__readeflags)
#pragma intrinsic(__segmentlimit)

int main(void)
{
   const unsigned long initsl = 0xbaadbabe;
   READETYPE eflags = 0;
   unsigned long sl = initsl;

   printf("Before: segment limit =0x%x eflags =0x%x\n", sl, eflags);
   sl = __segmentlimit(KGDT_R3_DATA + RPL_MASK);

   eflags = __readeflags();

   printf("After: segment limit =0x%x eflags =0x%x eflags.zf = %s\n", sl, eflags, (eflags & EFLAGS_ZF) ? "set" : "clear");

   // If ZF is set, the call to lsl succeeded; if ZF is clear, the call failed.
   printf("%s\n", eflags & EFLAGS_ZF ? "Success!": "Fail!");

   // You can verify the value of sl to make sure that the instruction wrote to it
   printf("sl was %s\n", (sl == initsl) ? "unchanged" : "changed");

   return 0;
}
Before: segment limit =0xbaadbabe eflags =0x0
After: segment limit =0xffffffff eflags =0x256 eflags.zf = set
Success!
sl was changed

END Microsoft 特定的

另請參閱

編譯程式內部函數