How are parameters passed in function calls in CIL?

I am trying to learn the CIL code, but I can’t understand how the return value of one function is passed as a parameter to another function.

I created the CIL code for the following function:

  public bool TestWebPage()
  {
    WebRequest request = WebRequest.Create("http://www.costco.com");
    request.Proxy.Credentials = CredentialCache.DefaultCredentials;
  }

CIL Code:

//000021:     public void TestWebPage()
//000022:     {
    IL_0000:  /* 00   |                  */ nop
   .line 23,23 : 7,71 ''
//000023:       WebRequest request = WebRequest.Create("http://www.costco.com");
IL_0001:  /* 72   | (70)000001       */ ldstr      "http://www.costco.com" /* 70000001  */
  IL_0006:  /* 28   | (0A)000012       */ call       class [System/*23000003*/]System.Net.WebRequest/*01000016*/ [System/*23000003*/]System.Net.WebRequest/*01000016*/::Create(string) /* 0A000012 */
  IL_000b:  /* 0A   |                  */ stloc.0
.line 24,24 : 7,70 ''
//000024:       request.Proxy.Credentials = CredentialCache.DefaultCredentials;
IL_000c:  /* 06   |                  */ ldloc.0
IL_000d:  /* 6F   | (0A)000013       */ callvirt   instance class [System/*23000003*/]System.Net.IWebProxy/*01000017*/ [System/*23000003*/]System.Net.WebRequest/*01000016*/::get_Proxy() /* 0A000013 */
IL_0012:  /* 28   | (0A)000014       */ call       class [System/*23000003*/]System.Net.ICredentials/*01000019*/ [System/*23000003*/]System.Net.CredentialCache/*01000018*/::get_DefaultCredentials() /* 0A000014 */
IL_0017:  /* 6F   | (0A)000015       */ callvirt   instance void [System/*23000003*/]System.Net.IWebProxy/*01000017*/::set_Credentials(class [System/*23000003*/]System.Net.ICredentials/*01000019*/) /* 0A000015 */
IL_001c:  /* 00   |                  */ nop
.line 25,25 : 7,73 ''

In particular, I cannot understand the following things in CIL code:

  • How does the CLR runtime know that set_Credentials is passed the value returned from get_DefaultCredentials, since there seems to be no link other than the commented part of "/ 01000019 /"?

  • How the CLR calls get_Proxy in the current instance of System.Net.WebRequest, i.e. is there a pointer to the instance number in the CIL code?

+3
source share
3 answers

They are usually pushed onto the stack - but note that this is basically an implementation detail, p

1: , = :

  • ldloc.0
  • callvirt get_Proxy() ( ) ( )
  • call get_DefaultCredentials()
  • callvirt set_Credentials 2 ; () ( ); ( )

2: "" (.. ); loc 0. - , loc 0 , ; "dup" ( ), , , stloc/ldloc.

+2
  • call IL_0012 get_DefaultCredentials set_Credentials .
  • request, WebRequest.Create, 0 (stloc.0) ldloc.0, get_Proxy IL_000d , .
+1

. , , get_DefaultCredentials, .

, .

, , , , "http://www.costco.com" . . . , , . ldstr . , , 0 stloc.0 ( ).

, , , , ldloc.0. WebRequest . get_Proxy, , ldloc.0, . . , , , ldloc.0 .

, , .

0

All Articles