Monday, May 1, 2017

Pointer Arithmatic.

Adding an integer, say i, to a pointer is actually advancing the pointer to i unit of the underlying data type the pointer points to.  For example,

int *p;
p = &j
p = p + 3;  /* p = p + 3*4 as integer is 4 bytes in length */

Likewise, for subtraction, the pointer is deducted by i units of the underlying data type.

When subtracting 2 pointers, the result is the number of units of the underlying data type.  A minus result indicate the first pointer is less than the second pointer in the expression.

Constant and Ponter

const int *p is a pointer to a constant integer.  We cannot change the variable that the pointer is pointing to but we can change the pointer to point to another variable.  However, even if the new variable it points to is not a constant, C runtime will not allow us to change it as it thinks the pointer is pointing to a constant as declared.

For example

const int *p;
const int i = 100
int j = 20

p = &i;  /* ok */
p = &j;  /* ok */
*p = 300;  /* error */

int *const p is a constant point pointing to an integer variable.  The pointer value cannot be change but we can change the variable it points to.

*p = 100;  /* ok */
p = &j;  /* error */

const int *const p is a constant pointer pointing to a constant variable. When the pointer is declard, it must be initialized.

const int *const p = &i

const int *const *p is a pointer to a constant pointer to a constant integer variable

Reading C Pointer Declaration

Reading the pointer declaration backward is easier.

For example, int * p

p = p is a variable
* = p is a pointer variable
int = p is a pointer variable points to an integer

const int * p = a pointer to an constant intege

Wednesday, November 16, 2016

Javascript

JavaScript was created in Netscape and incorporated into Netscape browser in 1995.  It was initially called Mocha and Livescript. Later on a marketing deal was made between Netscape and Sun whom own Java, it was named to Javascript.  To justified for the name, all Java keywords are reserved words in Javascript.  Javascript's standard library also uses the naming convention as Java.  It'd Msth and Date functions also based on the standard class of Java 1.0 objects.  ECMA standardised Javascript and it is called ECMAscript.  So Javascript is like a dialect of ECMAscript.  Likewise Microsoft's JScript is also a dialect of ECMAscript but there are some incompatibilities.

Monday, October 10, 2016

Greek Mythology

Orion

He is a son of king of Thrace whom was initially childless.  He was liked by Gods and in return, the Gods grant him a son.  They asked him for the hide of a bull he has scarified.  Zeus, Poseidon and Hermes urinated on the hide and buried it.  Nine month later, Orion was born from the spot and his father named him Urion or Orion, i.e. "urine boy".

Amazon

A tribe of worrier women who lived in distant shore of Black Sea.  When a child is born and is a boy, he would be killed.  If it was a girl, the tribe would accept it as one of them and raise it.  When the girl reached puberty, they would cut off her right breast for her to have a better draw of bow.  The "a" means no and "mazos" means breast.

Pan

Son of Hermes and a nymph called Dryope.  When he was born, the laughing child has feet of goat. horns and a full beard.  Hermes brought him to show to the Gods of Olympus and they were delighted, naming him Pan which mean "all" in Greek.  He chased a nymph called Syrinx whom ran way.  When pan nearly caught up, she prayed to the river nymph for help and they transform her to reed.  Pan cut the reed to different length and invented the pan pipe.  Pan would bring terror to those that offended him and thus "panic" means uncontrollable fear.


Sunday, July 24, 2016

Oracle redo and undo

Changing data in database generated both redo and undo records. The undo record is saved in the undo tablespace. These undo records provide the read consistency feature will allow another transaction to refers to the old version of data while it is being changed (and not committed) depending on the isolation level. The undo record is also used for roll back. The undo record is tied to the data block via pointers (undo block address and record number). The pointer is recorded in the interested transaction list with a limited size. When the list is exceeded, oracle will return error message saying old version data is not accessible. 

Writing the undo record to undo tablespace generated redo records too. The redo records for the real change and the undo record are combined when writing to the log files. 

Each transaction has a private redo (strand) and undo buffer to reduce latch contention to the public redo log buffer. The redo and undo record will be written to the public buffer when transaction commits. 

Tuesday, July 7, 2015

Windows System Calls

User mode program access system services via the API exposed in ntdll.  ntdll places the number representing the target system service defined in SSDT (System Service Dispatch Table). into eax.  It then call a common stub to transit to kernel mode

mov eax,18Ch ; target services
mov edx, offset ..... ; common stub address
call [edx]

The common stub resides in the ntdll!FastSystemCall module.  It executes the sysenter (or syscall for x64) to switch to kernel mode.  It will also save the esp (user mode stack pointer) to edx.  sysenter will load the cs, eip and esp (kernel mode stack) from the corresponding msr (model specific register).

Eventually the call will end up in the corresponding kernel mode modul in nt executive.