A temporary resident permit (TRP) is issued to a person who is inadmissible to Canada (criminality, misrepresentation etc). Even if you are from a visa-exempt country (ie. you do not need a visit visa to enter Canada) and you have been found inadmissible, you will likely have to apply for a TRP. TRPs only granted where the reason to travel to Canada is justified in the circumstance (family, employment, etc).You can apply for a TRP at a certain Canadian port of entries (at the land, air or sea border) or at the Canadian visa office in your country or region. Whether it is a Canada Border Services Agency (CBSA) officer or a Citizenship and Immigration (CIC) Officer who reviews your application, they will be looking at a couple of things:
whether your need to enter and stay in Canada outweighs any health or safety risks to Canadian society;
that your visit is justified by the circumstances.
A TRP can be issued for the time it takes for you to complete the purpose of your travel to Canada. You must either leave on or before the expiry of your TRP or apply for a new one before your TRP expires.
If you are inadmissible and are submitting a permanent residence application, you might need to also apply for a TRP. In these cases, the process is different than the above and you will need to consult with an immigration lawyer to set up the best strategy for you.
The right to remain in Canada as a visitor is never absolute and an officer can cancel your permit at any time.
Here are some other resources if you have been denied entry to Canada.