2005-04-16 15:20:36 -07:00
/ *
* This f i l e i s s u b j e c t t o t h e t e r m s a n d c o n d i t i o n s o f t h e G N U G e n e r a l P u b l i c
* License. S e e t h e f i l e " C O P Y I N G " i n t h e m a i n d i r e c t o r y o f t h i s a r c h i v e
* for m o r e d e t a i l s .
*
2013-03-25 13:41:18 -05:00
* Copyright ( C ) 1 9 9 6 , 1 9 9 9 b y R a l f B a e c h l e
* Copyright ( C ) 2 0 1 1 M I P S T e c h n o l o g i e s , I n c .
2005-04-16 15:20:36 -07:00
* /
# include < l i n u x / e r r n o . h >
# include < a s m / a s m . h >
2005-09-09 22:32:31 +02:00
# include < a s m / a s m - o f f s e t s . h >
2005-04-16 15:20:36 -07:00
# include < a s m / r e g d e f . h >
# define E X ( i n s n ,r e g ,a d d r ,h a n d l e r ) \
9 : insn r e g , a d d r ; \
.section _ _ ex_ t a b l e ," a " ; \
PTR 9 b , h a n d l e r ; \
.previous
/ *
* Returns : - EFAULT i f e x c e p t i o n b e f o r e t e r m i n a t o r , N i f t h e e n t i r e
* buffer f i l l e d , e l s e s t r l e n .
* /
/ *
* Ugly s p e c i a l c a s e h a v e t o c h e c k : w e m i g h t g e t p a s s e d a u s e r s p a c e
2013-01-22 12:59:30 +01:00
* pointer w h i c h w r a p s i n t o t h e k e r n e l s p a c e . W e d o n ' t d e a l w i t h t h a t . I f
2005-04-16 15:20:36 -07:00
* it h a p p e n s a t m o s t s o m e b y t e s o f t h e e x c e p t i o n s h a n d l e r s w i l l b e c o p i e d .
* /
2014-01-02 16:36:49 +00:00
.macro __BUILD_STRNCPY_ASM func
LEAF( _ _ s t r n c p y _ f r o m _ \ f u n c \ ( ) _ a s m )
2005-04-16 15:20:36 -07:00
LONG_ L v0 , T I _ A D D R _ L I M I T ( $ 2 8 ) # p o i n t e r o k ?
and v0 , a1
2014-01-02 16:36:49 +00:00
bnez v0 , . L f a u l t \ @
2005-04-16 15:20:36 -07:00
2014-01-02 16:36:49 +00:00
FEXPORT( _ _ s t r n c p y _ f r o m _ \ f u n c \ ( ) _ n o c h e c k _ a s m )
2013-03-25 13:41:18 -05:00
move t 0 , z e r o
move v1 , a1
2014-01-02 16:40:20 +00:00
.ifeqs " \ func" ," k e r n e l "
2014-01-02 16:36:49 +00:00
1 : EX( l b u , v0 , ( v1 ) , . L f a u l t \ @)
2014-01-02 16:40:20 +00:00
.else
1 : EX( l b u e , v0 , ( v1 ) , . L f a u l t \ @)
.endif
2005-04-16 15:20:36 -07:00
PTR_ A D D I U v1 , 1
2007-11-25 11:47:56 +01:00
R1 0 K C B A R R I E R ( 0 ( r a ) )
2014-04-04 03:32:29 +01:00
sb v0 , ( a0 )
2013-03-25 13:41:18 -05:00
beqz v0 , 2 f
PTR_ A D D I U t 0 , 1
2014-04-04 03:32:29 +01:00
PTR_ A D D I U a0 , 1
2013-03-25 13:41:18 -05:00
bne t 0 , a2 , 1 b
2 : PTR_ A D D U v0 , a1 , t 0
xor v0 , a1
2014-01-02 16:36:49 +00:00
bltz v0 , . L f a u l t \ @
2014-04-04 03:32:29 +01:00
move v0 , t 0
2005-04-16 15:20:36 -07:00
jr r a # r e t u r n n
2014-01-02 16:36:49 +00:00
END( _ _ s t r n c p y _ f r o m _ \ f u n c \ ( ) _ a s m )
2005-04-16 15:20:36 -07:00
2014-04-04 03:32:29 +01:00
.Lfault \ @:
li v0 , - E F A U L T
jr r a
2005-04-16 15:20:36 -07:00
.section _ _ ex_ t a b l e ," a "
2014-01-02 16:36:49 +00:00
PTR 1 b , . L f a u l t \ @
2005-04-16 15:20:36 -07:00
.previous
2014-01-02 16:36:49 +00:00
.endm
2014-01-02 16:40:20 +00:00
# ifndef C O N F I G _ E V A
/* Set aliases */
.global __strncpy_from_user_asm
.global __strncpy_from_user_nocheck_asm
.set _ _ strncpy_ f r o m _ u s e r _ a s m , _ _ s t r n c p y _ f r o m _ k e r n e l _ a s m
.set _ _ strncpy_ f r o m _ u s e r _ n o c h e c k _ a s m , _ _ s t r n c p y _ f r o m _ k e r n e l _ n o c h e c k _ a s m
# endif
_ _ BUILD_ S T R N C P Y _ A S M k e r n e l
# ifdef C O N F I G _ E V A
.set push
.set eva
2014-01-02 16:36:49 +00:00
_ _ BUILD_ S T R N C P Y _ A S M u s e r
2014-01-02 16:40:20 +00:00
.set pop
# endif