Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sXVLD-004P0u-Cp for pgsql-general@arkaria.postgresql.org; Sat, 27 Jul 2024 00:31:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sXVKC-001M0c-UC for pgsql-general@arkaria.postgresql.org; Sat, 27 Jul 2024 00:30:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sXVKC-001M0T-Hs for pgsql-general@lists.postgresql.org; Sat, 27 Jul 2024 00:30:16 +0000 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sXVK9-001fDx-Ps for pgsql-general@lists.postgresql.org; Sat, 27 Jul 2024 00:30:15 +0000 Received: by mail-io1-xd32.google.com with SMTP id ca18e2360f4ac-81f932ede28so6422339f.2 for ; Fri, 26 Jul 2024 17:30:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722040211; x=1722645011; darn=lists.postgresql.org; h=mime-version:content-language:accept-language:message-id:date :thread-index:thread-topic:subject:to:from:from:to:cc:subject:date :message-id:reply-to; bh=souU3LHBquM/rEoz2dLFxn6A1SF41zZz85uZa7OMfAU=; b=QL68wlSYpvs/H/mp1nKCS6rOnE5pikgNmM+IWo9q/3FDU0xZJ0nVTIQAWUh9UyEjt+ 2QHygBB4ZTkceFySsAb1Rs5w6vbLFvaQDhpeRPr5pkYj9nrXwnUjzuPnY4vLddKM8DJX aMw0OCJqGLeJ+w+w0SSBXPH6JTgYBsgZsVvVEOKDIBU3R0NSRR07Fk+rKRwl0BmOUyFe eVVIP5CYRZjKtcuCQnwbYvx27zKS+vikEzjdu5fSJK6SIi63yg6KYCNr3l9wbCDEEGZS qKi5K+1gwB1/hZTBRyVQYIB1jIZYQbyIxdQ7Qlk2lrYKV4eO4o6d5UpRC+s+vbgkHJ5n GM4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722040211; x=1722645011; h=mime-version:content-language:accept-language:message-id:date :thread-index:thread-topic:subject:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=souU3LHBquM/rEoz2dLFxn6A1SF41zZz85uZa7OMfAU=; b=nCDurjw4BwVyRHoJlpZhESeDiJ0pyoxL55yWV9BvubuYy/nxeRPMsGZqwacTXik4fA XYRFN1bUrQLY12ymIYazQmKQROT0/pIeoEi5xYd0pgfuMGbaFku2ii6tUazRVkvtrJ13 1ZhUPrko+YrKPJ/0QLWmcAAcTUM3p/Al3agrnSddqiEiG4MZzlI9jjmoXVtTQdLZN3bv kjG+O6uNAm4NS7f+cCGNAyQHZUHW0gEbl258weDuRtnVep3hwli5qVlO2v4w2u3cVr+U kThOD6Yr271xmmduAy3jpnOJU37rfhuEz4gX8ZuYmW3UVYRm8DnUwU2XEr/oG2weLXFB HGiA== X-Gm-Message-State: AOJu0YyTzGHwmZeAqgz2vkPNjEZFEnN0cjaGUjRWxCMihMMNg2XNUlqm 9LHfTmmhUg+zV3VuShNZEy/MfVxpO9e08udKArQiKflvVQafK5DWTbEhiA== X-Google-Smtp-Source: AGHT+IFxPCNMAXnNoQcOjVyNH0doQl37k2xlPkDbEn7vdIoKMA7KCeEgKRLM0T2CY53ERA98bDnIrw== X-Received: by 2002:a05:6e02:1c42:b0:383:17f9:6223 with SMTP id e9e14a558f8ab-39a22cc25b5mr52805905ab.2.1722040210880; Fri, 26 Jul 2024 17:30:10 -0700 (PDT) Received: from CH3PR10MB7834.namprd10.prod.outlook.com ([2603:1036:304:3080::5]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c29fa9f826sm1092699173.66.2024.07.26.17.30.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jul 2024 17:30:10 -0700 (PDT) From: Aditya Gupta To: "pgsql-general@lists.postgresql.org" Subject: Unexpected Null Pointer For Static Shared Memory Segment Thread-Topic: Unexpected Null Pointer For Static Shared Memory Segment Thread-Index: AQHa37wF6VBeURPFIUKGQq75J0bNJQ== X-MS-Exchange-MessageSentRepresentingType: 1 Date: Sat, 27 Jul 2024 00:30:09 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-Exchange-Organization-SCL: -1 X-MS-TNEF-Correlator: X-MS-Exchange-Organization-RecordReviewCfmType: 0 Content-Type: multipart/alternative; boundary="_000_CH3PR10MB7834D2B5AAA7C599DB321E17F1B52CH3PR10MB7834namp_" MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --_000_CH3PR10MB7834D2B5AAA7C599DB321E17F1B52CH3PR10MB7834namp_ Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Hello, I hope this message finds you well. I am currently working on a PostgreSQL = extension and have encountered an issue where a static pointer becomes null= between different AM routines. My problem is as follows: I am working with a few AM routines, specifically =93ambuild=94 and =93amre= scan=94. During =93ambuild=94, I use =93ShmemInitStruct=94 to initialize a = segment of shared memory and save the pointer to this location in my static= , global pointer. I then set some values of the structure that the pointer = points to, which I believe works correctly. I have ensured to acquire, and = later release, the =93AddinShmemInitLock=94 as well as check if we have fou= nd a segment of the same name in shared memory. I can access the pointer an= d any data I save in the struct perfectly fine during this AM routine. When the extension later performs =93amrescan=94, the static pointer I had = set is null. I am not quite sure why this is happening. I would greatly app= reciate any guidance or suggestions! Perhaps I need to use the startup hook= s when calling the =93ShmemInitStruct=94 function (although I would like to= avoid this as the size of the segment I am initializing varies at run time= ) or use dynamic shared memory? Please let me know if there are any more details I can provide or if anythi= ng is unclear. This is my first time working on a PostgreSQL extension and = asking a question using this mailing list, so please let me know if there i= s a more appropriate forum I should use. Thanks for your time and assistance! Best, Aditya Gupta --_000_CH3PR10MB7834D2B5AAA7C599DB321E17F1B52CH3PR10MB7834namp_ Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable

Hel= lo,

&nb= sp;

I h= ope this message finds you well. I am currently working on a PostgreSQL ext= ension and have encountered an issue where a static pointer becomes null be= tween different AM routines. My problem is as follows:

&nb= sp;

I a= m working with a few AM routines, specifically =93ambuild=94 and =93amresca= n=94. During =93ambuild=94, I use =93ShmemInitStruct=94 to initialize a seg= ment of shared memory and save the pointer to this location in my static, global pointer. I then set some values of the structure that= the pointer points to, which I believe works correctly. I have ensured to = acquire, and later release, the =93AddinShmemInitLock=94 as well as check i= f we have found a segment of the same name in shared memory. I can access the pointer and any data I save in the= struct perfectly fine during this AM routine. 

&nb= sp;

Whe= n the extension later performs =93amrescan=94, the static pointer I had set= is null. I am not quite sure why this is happening. I would greatly apprec= iate any guidance or suggestions! Perhaps I need to use the startup hooks when calling the =93ShmemInitStruct=94 fun= ction (although I would like to avoid this as the size of the segment I am = initializing varies at run time) or use dynamic shared memory?

&nb= sp;

Ple= ase let me know if there are any more details I can provide or if anything = is unclear. This is my first time working on a PostgreSQL extension and ask= ing a question using this mailing list, so please let me know if there is a more appropriate forum I should use.

&nb= sp;

Tha= nks for your time and assistance!

&nb= sp;

Bes= t,

Adi= tya Gupta

 

--_000_CH3PR10MB7834D2B5AAA7C599DB321E17F1B52CH3PR10MB7834namp_--