@@ -94,9 +94,6 @@ bool Log_disconnections = false;
94
94
95
95
int log_statement = LOGSTMT_NONE ;
96
96
97
- /* GUC variable for maximum stack depth (measured in kilobytes) */
98
- int max_stack_depth = 100 ;
99
-
100
97
/* wait N seconds to allow attach from a debugger */
101
98
int PostAuthDelay = 0 ;
102
99
@@ -124,15 +121,6 @@ typedef struct BindParamCbData
124
121
* ----------------
125
122
*/
126
123
127
- /* max_stack_depth converted to bytes for speed of checking */
128
- static long max_stack_depth_bytes = 100 * 1024L ;
129
-
130
- /*
131
- * Stack base pointer -- initialized by PostmasterMain and inherited by
132
- * subprocesses (but see also InitPostmasterChild).
133
- */
134
- static char * stack_base_ptr = NULL ;
135
-
136
124
/*
137
125
* Flag to keep track of whether we have started a transaction.
138
126
* For extended query protocol this has to be remembered across messages.
@@ -3513,133 +3501,6 @@ ProcessInterrupts(void)
3513
3501
HandleParallelApplyMessages ();
3514
3502
}
3515
3503
3516
- /*
3517
- * set_stack_base: set up reference point for stack depth checking
3518
- *
3519
- * Returns the old reference point, if any.
3520
- */
3521
- pg_stack_base_t
3522
- set_stack_base (void )
3523
- {
3524
- #ifndef HAVE__BUILTIN_FRAME_ADDRESS
3525
- char stack_base ;
3526
- #endif
3527
- pg_stack_base_t old ;
3528
-
3529
- old = stack_base_ptr ;
3530
-
3531
- /*
3532
- * Set up reference point for stack depth checking. On recent gcc we use
3533
- * __builtin_frame_address() to avoid a warning about storing a local
3534
- * variable's address in a long-lived variable.
3535
- */
3536
- #ifdef HAVE__BUILTIN_FRAME_ADDRESS
3537
- stack_base_ptr = __builtin_frame_address (0 );
3538
- #else
3539
- stack_base_ptr = & stack_base ;
3540
- #endif
3541
-
3542
- return old ;
3543
- }
3544
-
3545
- /*
3546
- * restore_stack_base: restore reference point for stack depth checking
3547
- *
3548
- * This can be used after set_stack_base() to restore the old value. This
3549
- * is currently only used in PL/Java. When PL/Java calls a backend function
3550
- * from different thread, the thread's stack is at a different location than
3551
- * the main thread's stack, so it sets the base pointer before the call, and
3552
- * restores it afterwards.
3553
- */
3554
- void
3555
- restore_stack_base (pg_stack_base_t base )
3556
- {
3557
- stack_base_ptr = base ;
3558
- }
3559
-
3560
- /*
3561
- * check_stack_depth/stack_is_too_deep: check for excessively deep recursion
3562
- *
3563
- * This should be called someplace in any recursive routine that might possibly
3564
- * recurse deep enough to overflow the stack. Most Unixen treat stack
3565
- * overflow as an unrecoverable SIGSEGV, so we want to error out ourselves
3566
- * before hitting the hardware limit.
3567
- *
3568
- * check_stack_depth() just throws an error summarily. stack_is_too_deep()
3569
- * can be used by code that wants to handle the error condition itself.
3570
- */
3571
- void
3572
- check_stack_depth (void )
3573
- {
3574
- if (stack_is_too_deep ())
3575
- {
3576
- ereport (ERROR ,
3577
- (errcode (ERRCODE_STATEMENT_TOO_COMPLEX ),
3578
- errmsg ("stack depth limit exceeded" ),
3579
- errhint ("Increase the configuration parameter \"max_stack_depth\" (currently %dkB), "
3580
- "after ensuring the platform's stack depth limit is adequate." ,
3581
- max_stack_depth )));
3582
- }
3583
- }
3584
-
3585
- bool
3586
- stack_is_too_deep (void )
3587
- {
3588
- char stack_top_loc ;
3589
- long stack_depth ;
3590
-
3591
- /*
3592
- * Compute distance from reference point to my local variables
3593
- */
3594
- stack_depth = (long ) (stack_base_ptr - & stack_top_loc );
3595
-
3596
- /*
3597
- * Take abs value, since stacks grow up on some machines, down on others
3598
- */
3599
- if (stack_depth < 0 )
3600
- stack_depth = - stack_depth ;
3601
-
3602
- /*
3603
- * Trouble?
3604
- *
3605
- * The test on stack_base_ptr prevents us from erroring out if called
3606
- * during process setup or in a non-backend process. Logically it should
3607
- * be done first, but putting it here avoids wasting cycles during normal
3608
- * cases.
3609
- */
3610
- if (stack_depth > max_stack_depth_bytes &&
3611
- stack_base_ptr != NULL )
3612
- return true;
3613
-
3614
- return false;
3615
- }
3616
-
3617
- /* GUC check hook for max_stack_depth */
3618
- bool
3619
- check_max_stack_depth (int * newval , void * * extra , GucSource source )
3620
- {
3621
- long newval_bytes = * newval * 1024L ;
3622
- long stack_rlimit = get_stack_depth_rlimit ();
3623
-
3624
- if (stack_rlimit > 0 && newval_bytes > stack_rlimit - STACK_DEPTH_SLOP )
3625
- {
3626
- GUC_check_errdetail ("\"max_stack_depth\" must not exceed %ldkB." ,
3627
- (stack_rlimit - STACK_DEPTH_SLOP ) / 1024L );
3628
- GUC_check_errhint ("Increase the platform's stack depth limit via \"ulimit -s\" or local equivalent." );
3629
- return false;
3630
- }
3631
- return true;
3632
- }
3633
-
3634
- /* GUC assign hook for max_stack_depth */
3635
- void
3636
- assign_max_stack_depth (int newval , void * extra )
3637
- {
3638
- long newval_bytes = newval * 1024L ;
3639
-
3640
- max_stack_depth_bytes = newval_bytes ;
3641
- }
3642
-
3643
3504
/*
3644
3505
* GUC check_hook for client_connection_check_interval
3645
3506
*/
@@ -5099,40 +4960,6 @@ forbidden_in_wal_sender(char firstchar)
5099
4960
}
5100
4961
5101
4962
5102
- /*
5103
- * Obtain platform stack depth limit (in bytes)
5104
- *
5105
- * Return -1 if unknown
5106
- */
5107
- long
5108
- get_stack_depth_rlimit (void )
5109
- {
5110
- #if defined(HAVE_GETRLIMIT )
5111
- static long val = 0 ;
5112
-
5113
- /* This won't change after process launch, so check just once */
5114
- if (val == 0 )
5115
- {
5116
- struct rlimit rlim ;
5117
-
5118
- if (getrlimit (RLIMIT_STACK , & rlim ) < 0 )
5119
- val = -1 ;
5120
- else if (rlim .rlim_cur == RLIM_INFINITY )
5121
- val = LONG_MAX ;
5122
- /* rlim_cur is probably of an unsigned type, so check for overflow */
5123
- else if (rlim .rlim_cur >= LONG_MAX )
5124
- val = LONG_MAX ;
5125
- else
5126
- val = rlim .rlim_cur ;
5127
- }
5128
- return val ;
5129
- #else
5130
- /* On Windows we set the backend stack size in src/backend/Makefile */
5131
- return WIN32_STACK_RLIMIT ;
5132
- #endif
5133
- }
5134
-
5135
-
5136
4963
static struct rusage Save_r ;
5137
4964
static struct timeval Save_t ;
5138
4965
0 commit comments