TianoCore EDK2 master
Loading...
Searching...
No Matches
SafeIntLibEbc.c
Go to the documentation of this file.
1
12#include <Base.h>
13#include <Library/SafeIntLib.h>
14
35RETURN_STATUS
36EFIAPI
38 IN INT32 Operand,
39 OUT UINTN *Result
40 )
41{
42 if (sizeof (UINTN) == sizeof (UINT32)) {
43 return SafeInt32ToUint32 (Operand, (UINT32 *)Result);
44 }
45
46 return SafeInt32ToUint64 (Operand, (UINT64 *)Result);
47}
48
69RETURN_STATUS
70EFIAPI
72 IN UINT32 Operand,
73 OUT INTN *Result
74 )
75{
76 if (Result == NULL) {
78 }
79
80 if (sizeof (UINTN) == sizeof (UINT32)) {
81 return SafeUint32ToInt32 (Operand, (INT32 *)Result);
82 }
83
84 *Result = Operand;
85 return RETURN_SUCCESS;
86}
87
108RETURN_STATUS
109EFIAPI
111 IN INTN Operand,
112 OUT INT32 *Result
113 )
114{
115 if (Result == NULL) {
117 }
118
119 if (sizeof (UINTN) == sizeof (UINT32)) {
120 *Result = (INT32)Operand;
121 return RETURN_SUCCESS;
122 }
123
124 return SafeInt64ToInt32 ((INT64)Operand, Result);
125}
126
147RETURN_STATUS
148EFIAPI
150 IN INTN Operand,
151 OUT UINT32 *Result
152 )
153{
154 RETURN_STATUS Status;
155
156 if (Result == NULL) {
158 }
159
160 if (sizeof (UINTN) == sizeof (UINT32)) {
161 if (Operand >= 0) {
162 *Result = (UINT32)Operand;
163 Status = RETURN_SUCCESS;
164 } else {
165 *Result = UINT32_ERROR;
167 }
168
169 return Status;
170 }
171
172 return SafeInt64ToUint32 ((INT64)Operand, Result);
173}
174
195RETURN_STATUS
196EFIAPI
198 IN UINTN Operand,
199 OUT UINT32 *Result
200 )
201{
202 if (Result == NULL) {
204 }
205
206 if (sizeof (UINTN) == sizeof (UINT32)) {
207 *Result = (UINT32)Operand;
208 return RETURN_SUCCESS;
209 }
210
211 return SafeUint64ToUint32 ((UINT64)Operand, Result);
212}
213
234RETURN_STATUS
235EFIAPI
237 IN UINTN Operand,
238 OUT INT64 *Result
239 )
240{
241 if (Result == NULL) {
243 }
244
245 if (sizeof (UINTN) == sizeof (UINT32)) {
246 *Result = (INT64)Operand;
247 return RETURN_SUCCESS;
248 }
249
250 return SafeUint64ToInt64 ((UINT64)Operand, Result);
251}
252
273RETURN_STATUS
274EFIAPI
276 IN INT64 Operand,
277 OUT INTN *Result
278 )
279{
280 if (Result == NULL) {
282 }
283
284 if (sizeof (UINTN) == sizeof (UINT32)) {
285 return SafeInt64ToInt32 (Operand, (INT32 *)Result);
286 }
287
288 *Result = (INTN)Operand;
289 return RETURN_SUCCESS;
290}
291
312RETURN_STATUS
313EFIAPI
315 IN INT64 Operand,
316 OUT UINTN *Result
317 )
318{
319 if (sizeof (UINTN) == sizeof (UINT32)) {
320 return SafeInt64ToUint32 (Operand, (UINT32 *)Result);
321 }
322
323 return SafeInt64ToUint64 (Operand, (UINT64 *)Result);
324}
325
346RETURN_STATUS
347EFIAPI
349 IN UINT64 Operand,
350 OUT UINTN *Result
351 )
352{
353 if (Result == NULL) {
355 }
356
357 if (sizeof (UINTN) == sizeof (UINT32)) {
358 return SafeUint64ToUint32 ((UINT64)Operand, (UINT32 *)Result);
359 }
360
361 *Result = Operand;
362 return RETURN_SUCCESS;
363}
364
386RETURN_STATUS
387EFIAPI
389 IN UINTN Augend,
390 IN UINTN Addend,
391 OUT UINTN *Result
392 )
393{
394 RETURN_STATUS Status;
395
396 if (Result == NULL) {
398 }
399
400 if (sizeof (UINTN) == sizeof (UINT32)) {
401 if ((UINT32)(Augend + Addend) >= Augend) {
402 *Result = (Augend + Addend);
403 Status = RETURN_SUCCESS;
404 } else {
405 *Result = UINTN_ERROR;
407 }
408
409 return Status;
410 }
411
412 return SafeUint64Add ((UINT64)Augend, (UINT64)Addend, (UINT64 *)Result);
413}
414
436RETURN_STATUS
437EFIAPI
439 IN UINTN Minuend,
440 IN UINTN Subtrahend,
441 OUT UINTN *Result
442 )
443{
444 RETURN_STATUS Status;
445
446 if (Result == NULL) {
448 }
449
450 if (sizeof (UINTN) == sizeof (UINT32)) {
451 if (Minuend >= Subtrahend) {
452 *Result = (Minuend - Subtrahend);
453 Status = RETURN_SUCCESS;
454 } else {
455 *Result = UINTN_ERROR;
457 }
458
459 return Status;
460 }
461
462 return SafeUint64Sub ((UINT64)Minuend, (UINT64)Subtrahend, (UINT64 *)Result);
463}
464
486RETURN_STATUS
487EFIAPI
489 IN UINTN Multiplicand,
490 IN UINTN Multiplier,
491 OUT UINTN *Result
492 )
493{
494 UINT64 IntermediateResult;
495
496 if (sizeof (UINTN) == sizeof (UINT32)) {
497 IntermediateResult = ((UINT64)Multiplicand) *((UINT64)Multiplier);
498
499 return SafeUint64ToUintn (IntermediateResult, Result);
500 }
501
502 return SafeUint64Mult ((UINT64)Multiplicand, (UINT64)Multiplier, (UINT64 *)Result);
503}
504
526RETURN_STATUS
527EFIAPI
529 IN INTN Augend,
530 IN INTN Addend,
531 OUT INTN *Result
532 )
533{
534 if (sizeof (UINTN) == sizeof (UINT32)) {
535 return SafeInt64ToIntn (((INT64)Augend) + ((INT64)Addend), Result);
536 }
537
538 return SafeInt64Add ((INT64)Augend, (INT64)Addend, (INT64 *)Result);
539}
540
562RETURN_STATUS
563EFIAPI
565 IN INTN Minuend,
566 IN INTN Subtrahend,
567 OUT INTN *Result
568 )
569{
570 if (sizeof (UINTN) == sizeof (UINT32)) {
571 return SafeInt64ToIntn (((INT64)Minuend) - ((INT64)Subtrahend), Result);
572 }
573
574 return SafeInt64Sub ((INT64)Minuend, (INT64)Subtrahend, (INT64 *)Result);
575}
576
598RETURN_STATUS
599EFIAPI
601 IN INTN Multiplicand,
602 IN INTN Multiplier,
603 OUT INTN *Result
604 )
605{
606 if (sizeof (UINTN) == sizeof (UINT32)) {
607 return SafeInt64ToIntn (((INT64)Multiplicand) *((INT64)Multiplier), Result);
608 }
609
610 return SafeInt64Mult ((INT64)Multiplicand, (INT64)Multiplier, (INT64 *)Result);
611}
UINT64 UINTN
INT64 INTN
#define NULL
Definition: Base.h:319
#define RETURN_BUFFER_TOO_SMALL
Definition: Base.h:1093
#define RETURN_SUCCESS
Definition: Base.h:1066
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define RETURN_INVALID_PARAMETER
Definition: Base.h:1076
RETURN_STATUS EFIAPI SafeInt64ToInt32(IN INT64 Operand, OUT INT32 *Result)
Definition: SafeIntLib.c:2302
RETURN_STATUS EFIAPI SafeUint32ToInt32(IN UINT32 Operand, OUT INT32 *Result)
Definition: SafeIntLib.c:1422
RETURN_STATUS EFIAPI SafeInt32ToUint32(IN INT32 Operand, OUT UINT32 *Result)
Definition: SafeIntLib.c:1114
RETURN_STATUS EFIAPI SafeInt32ToUint64(IN INT32 Operand, OUT UINT64 *Result)
Definition: SafeIntLib.c:1158
RETURN_STATUS EFIAPI SafeInt64ToUint32(IN INT64 Operand, OUT UINT32 *Result)
Definition: SafeIntLib.c:2346
RETURN_STATUS EFIAPI SafeInt64Mult(IN INT64 Multiplicand, IN INT64 Multiplier, OUT INT64 *Result)
Definition: SafeIntLib.c:4094
RETURN_STATUS EFIAPI SafeUint64Sub(IN UINT64 Minuend, IN UINT64 Subtrahend, OUT UINT64 *Result)
Definition: SafeIntLib.c:3161
RETURN_STATUS EFIAPI SafeUint64Add(IN UINT64 Augend, IN UINT64 Addend, OUT UINT64 *Result)
Definition: SafeIntLib.c:2973
RETURN_STATUS EFIAPI SafeUint64Mult(IN UINT64 Multiplicand, IN UINT64 Multiplier, OUT UINT64 *Result)
Definition: SafeIntLib.c:3319
RETURN_STATUS EFIAPI SafeInt64Add(IN INT64 Augend, IN INT64 Addend, OUT INT64 *Result)
Definition: SafeIntLib.c:3613
RETURN_STATUS EFIAPI SafeInt64ToUint64(IN INT64 Operand, OUT UINT64 *Result)
Definition: SafeIntLib.c:2390
RETURN_STATUS EFIAPI SafeUint64ToInt64(IN UINT64 Operand, OUT INT64 *Result)
Definition: SafeIntLib.c:2786
RETURN_STATUS EFIAPI SafeUint64ToUint32(IN UINT64 Operand, OUT UINT32 *Result)
Definition: SafeIntLib.c:2698
RETURN_STATUS EFIAPI SafeInt64Sub(IN INT64 Minuend, IN INT64 Subtrahend, OUT INT64 *Result)
Definition: SafeIntLib.c:3857
RETURN_STATUS EFIAPI SafeInt64ToIntn(IN INT64 Operand, OUT INTN *Result)
RETURN_STATUS EFIAPI SafeUint32ToIntn(IN UINT32 Operand, OUT INTN *Result)
Definition: SafeIntLibEbc.c:71
RETURN_STATUS EFIAPI SafeUintnAdd(IN UINTN Augend, IN UINTN Addend, OUT UINTN *Result)
RETURN_STATUS EFIAPI SafeIntnToInt32(IN INTN Operand, OUT INT32 *Result)
RETURN_STATUS EFIAPI SafeUintnMult(IN UINTN Multiplicand, IN UINTN Multiplier, OUT UINTN *Result)
RETURN_STATUS EFIAPI SafeIntnToUint32(IN INTN Operand, OUT UINT32 *Result)
RETURN_STATUS EFIAPI SafeUintnToUint32(IN UINTN Operand, OUT UINT32 *Result)
RETURN_STATUS EFIAPI SafeIntnMult(IN INTN Multiplicand, IN INTN Multiplier, OUT INTN *Result)
RETURN_STATUS EFIAPI SafeIntnSub(IN INTN Minuend, IN INTN Subtrahend, OUT INTN *Result)
RETURN_STATUS EFIAPI SafeUintnToInt64(IN UINTN Operand, OUT INT64 *Result)
RETURN_STATUS EFIAPI SafeInt32ToUintn(IN INT32 Operand, OUT UINTN *Result)
Definition: SafeIntLibEbc.c:37
RETURN_STATUS EFIAPI SafeIntnAdd(IN INTN Augend, IN INTN Addend, OUT INTN *Result)
RETURN_STATUS EFIAPI SafeInt64ToUintn(IN INT64 Operand, OUT UINTN *Result)
RETURN_STATUS EFIAPI SafeUint64ToUintn(IN UINT64 Operand, OUT UINTN *Result)
RETURN_STATUS EFIAPI SafeUintnSub(IN UINTN Minuend, IN UINTN Subtrahend, OUT UINTN *Result)